<!-- 课程简介信息表 -->
<?php require_once 'header.php'; ?>

<?php 
session_start();
if (empty($_SESSION['status'])||empty($_SESSION['id'])||empty($_SESSION['name'])) {
  echo "<script>window.location.href='signin.php';</script>";
}
 ?>
 <div class="container">
  <?php 
  if (!empty($_GET['term'])) {
  
  	require_once 'connect.php';
    $term=$_GET['term'];
   ?>
	
<script>
$("title").html("课程信息");
</script>
<ul class="nav nav-tabs nav-justified">
    <li role="presentation"><a href="./"><img src="./img/home1.jpg" alt=""></a></li>
</ul>
<h1 class="text-center">
	<?php echo $term; ?>课程信息
</h1>

<div class="pull-right">

 <form action="./" method="get">
 <button type="button" class="btn btn-success" data-toggle="modal" data-target=".bs-me-modal-sm"><?php echo $_SESSION['name']; ?></button>
  <input type="hidden" name="zhuxiao" value="zhuxiao">
  <button type="submit" class="btn btn-danger">注销</button>
</form>

<div class="modal fade bs-me-modal-sm" tabindex="-1" role="dialog" aria-labelledby="mySmallModalLabel" aria-hidden="true">
  <div class="modal-dialog modal-sm">
    <div class="modal-content">
      <div class="modal-header">
          <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
          <h4 class="modal-title" id="gridSystemModalLabel"><?php echo $_SESSION['name']; ?></h4>
        </div>
        <?php //修改个人信息
          require_once 'connect.php';
          $class=$_SESSION['status'];
          $className="";
          switch ($class) {
            case 1:
            $className="administrations";
              break;
            case 2:
            $className="teachers";
             break;
            case 3:
            $className="students";
              break;
            default:
              
              break;
          }
          $query="select * from ".$className." where id=".$_SESSION['id'];
          $result=$mysql->query($query);
          $row=$result->fetch_assoc();

          if ((!empty($_POST['email']))&&(!empty($_POST['password']))){
            $brief=empty($_POST['brief'])?NULL:$_POST['brief'];
            $queryChange="update ".$className." set email='".$_POST['email']."', password='".$_POST['password']."', brief='".$brief."'";
            $resultChange=$mysql->query($queryChange);
            if ($resultChange) {
              echo "<script>alert('修改成功！');</script>";

            }else{
              echo "<script>alert('修改失败！')</script>";
            }
          }
         ?>
        <form action="./" method="post">
        <div class="modal-body">
        	

         <div class="form-group">
            <label for="inputEmail" class="control-label">邮箱</label>
            <div class="">
               <input type="email" id="inputEmail" class="form-control" placeholder="Email address" name="email" value="<?php echo $row['email']; ?>" required>
            </div>
          </div> 
        
        <div class="form-group">
            <label for="inputPassword" class="control-label">密码</label>
            <div class="">
                <input type="password" id="inputPassword" class="form-control" placeholder="Password" name="password" value="<?php echo $row['password']; ?>" required>
            </div>
          </div> 

          <div class="form-group">
            <label class="control-label">简介</label>
            <div class="">
               <textarea class="form-control" rows="3" name="brief"><?php echo $row['brief']; ?></textarea>
            </div>
          </div> 
        </div>
      <div class="modal-footer">
          <button class="btn btn-primary" type="submit">修改</button>
          <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
        </div>
        </form>
    </div>
  </div>
</div>

</div>


<table class="table table-striped table-hover">
				<thead>
		          <tr>
		            <th>
		              课程ID
		            </th>
		            <th>
		              课程名
		            </th>
		            <th>
		              课程内容
		            </th>
		            <th>
		              课程大纲
		            </th>
		            <th>
		              任课教师
		            </th>
		            <th>
		              用书
		            </th>
		            <th>
		              评价
		            </th>
		          </tr>
		        </thead>
				<tbody>
				<?php 
				$query="select lesson_id,lesson_name,content,main,name,book,sex,email,brief from teachers,lessons,teach where term='".$term."' and teach.lesson_id=lessons.id and teach.teachers_id=teachers.id;" ;
				    
				$result=$mysql->query($query);
			    if(!$result) echo "<script>window.location.href='error.php?num=1';</script>";//查询出错
			    if ($result->num_rows==0) {
			    	echo "<script>$('tbody').html('暂无课程信息！');</script>";
			    }
				for ($i=1; $i <= $result->num_rows ; $i++) { 
					$row=$result->fetch_assoc();
					
					echo "<tr><td>".$row['lesson_id']."</td><td>".$row['lesson_name']."</td><td>".$row['content']."</td><td>".$row['main']."</td>";
				 ?>
					<td>
				<button type="button" class="btn btn-primary" data-toggle="modal" data-target=".bs-<?php echo $i.$row['name']; ?>-modal-sm"><?php echo $row['name']; ?></button>
				<div class="modal fade bs-<?php echo $i.$row['name']; ?>-modal-sm" tabindex="-1" role="dialog" aria-labelledby="mySmallModalLabel" aria-hidden="true">
				  <div class="modal-dialog modal-sm">
				    <div class="modal-content">
					    <div class="modal-header">
				          <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
				          <h4 class="modal-title" id="gridSystemModalLabel"><?php echo $row['name']; ?></h4>
				        </div>
				       	<form action="" method="">
				        <div class="modal-body">
					        <div class="form-group">
					          <label>性别</label>
					          <p class="form-control-static"><?php echo $row['sex']=='m'?'男':'女'; ?></p>
					        </div>
					        <div class="form-group">
					          <label>邮箱</label>
					          <p class="form-control-static"><?php echo $row['email']; ?></p>
					        </div>
					        <div class="form-group">
					          <label>简介</label>
					          <p class="form-control-static"><?php echo $row['brief']; ?></p>
					        </div>
				      	</div>
				     	<div class="modal-footer">
				          <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
				        </div>
				        </form>
				    </div>
				  </div>
				</div>

					</td>

					<td><?php echo $row['book'];?></td>
					<td>
				<button type="button" class="btn btn-primary" data-toggle="modal" data-target=".bs-<?php echo $i; ?>-modal-sm">众说纷纭</button>
				<div class="modal fade bs-<?php echo $i; ?>-modal-sm" tabindex="-1" role="dialog" aria-labelledby="mySmallModalLabel" aria-hidden="true">
				  <div class="modal-dialog modal-sm">
				    <div class="modal-content">
					    <div class="modal-header">
				          <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
				          <h4 class="modal-title" id="gridSystemModalLabel">历史评价</h4>
				        </div>
				        <div class="modal-body">
				        	<?php 
				        	$queryValuation="select valuation_id,id,name, content, time, term from valuation,students where valuation.lesson_id=".$row['lesson_id']." and valuation.students_id=students.id order by valuation_id desc";
				        	$resultValuation=$mysql->query($queryValuation);
						    if(empty($resultValuation)||$resultValuation->num_rows==0){ echo "<div><p>暂无评价历史</p></div>";}//查询出错
						    else{
							for ($j=1; $j <= $resultValuation->num_rows ; $j++) { 
								$rowValuation=$resultValuation->fetch_assoc();
								echo "<div><p class='text-primary'><span class='label label-default'>".$j."</span>".$rowValuation['name']."</p><p class='text-info small'>".$rowValuation['time']." ".$rowValuation['term']."</p><p class='lead'>".$rowValuation['content']."</p>";
									?>

							<?php if ($rowValuation['id']==$_SESSION['id']): ?>
							<?php 
							// 评论删除
							if (!empty($_POST['delete'])) {
								$queryDelete="delete from valuation where valuation_id=".$_POST['delete'];
								$resultDelete=$mysql->query($queryDelete);
								echo "<script>window.location.replace(location.href);</script>";
							}
							 ?>
							 <form action="./lessons.php?term=<?php echo $term; ?>" method="post">
							  <input type="hidden" name="delete" value="<?php echo $rowValuation['valuation_id'] ?>">
							  <button type="submit" class="btn btn-danger">删除</button>
							</form>		
							<?php endif ?>
			
								</div><hr/><hr/>
							<?php
							}
							}
				        	 ?>
				        	 <?php 
				        	 if (!empty($_POST['valuation'])) {
				        	 	$queryMyValuation="insert into valuation values(NULL,".$_POST['lesson_id'].",".$_SESSION['id'].",'".$_POST['valuation']."','".$_POST['term']."',NOW())";
								$resultMyValuation=$mysql->query($queryMyValuation);
							    if ($resultMyValuation) {
							      echo "<script>alert('评价成功！');window.location.replace(location.href);</script>";
							    }else{
							      echo "<script>alert('评价失败！')</script>";
							    }
				        	 }
				        	  ?>
				        	  <?php if ($_SESSION['status']==3): ?>
				        	  	<form class="form-inline" action="./lessons.php?term=<?php echo $term; ?>" method="post">
					        	 <fieldset <?php echo $_SESSION['status']==3?"":"disabled"; ?>>
								  <div class="form-group">
								  	<input type="hidden" name="lesson_id" value="<?php echo $row['lesson_id']; ?>">
								  	<input type="hidden" name="term" value="<?php echo $term; ?>">
								    <input type="text" class="form-control" id="" placeholder="我也想评价" name="valuation">
								  </div>
								  <button type="submit" class="btn btn-default">提交</button>
								  </fieldset>
								</form>
				        	  <?php endif ?>
				        	 
				      	</div>
				     	<div class="modal-footer">
				          <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
				        </div>
				        
				    </div>
				  </div>
				</div>
					</td>

					</tr>
				<?php 	
				}
				 ?>
				</tbody>
			</table>
<?php 	
  }else{
  	echo "<script>window.location.href='error.php?num=1';</script>";
  	} ?>
</div>
<?php require_once 'footer.php'; ?>